Home:ALL Converter>Testing the Go model

Testing the Go model

Ask Time:2015-03-31T03:08:37         Author:chipmunk

Json Formatter

So this is one of my Go models:

type ObjectReference struct {
IRI           string    `json:"iri" bson:"iri"`
ObjectType    string    `json:"objectType" bson:"objectType,omitempty"`
ActivityType  string    `json:"activityType,omitempty" bson:"activityType,omitempty"`
Errors                  `bson:"-"`

}

I have a validation on the ActivityType as:

   objTypeSuccess := o.ObjectType == "activity"
success = success && objTypeSuccess
if (!objTypeSuccess) {
    o.errors = append(o.errors, "Object objectType supplied : " + o.ObjectType + " is invalid. Valid object types are : [activity]")
}

where

o *ObjectReference is in the func() definition 

I am trying to write a test as so:

        testObj = models.ObjectReference{
        // Invalid Obj Type
        IRI: "http://localhost:8001/launched",
        ObjectType: ????,
        ActivityType: testObjType,
    }

I don't quite understand how I could initialize the ObjectType in my testObj. Can someone help me with this?

Author:chipmunk,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29354257/testing-the-go-model
yy